import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Vant from 'vant';
import 'lib-flexible/flexible';
import { Tab, Tabs } from 'vant';
import { Popup } from 'vant';
import { Dialog } from 'vant';
Vue.use(Tab);
Vue.use(Tabs);
Vue.use(Popup);
Vue.use(Dialog);

import './plugins/axios'
import '../node_modules/vant/lib/index.css';

//require styles
Vue.config.productionTip = false
Vue.use(Vant);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')


//次数过滤器
Vue.filter('count', function (value) {
  if (!value) return ''
  return parseInt(value / 10000) >= 1 ?
    (value / 10000).toFixed(1) + "w" :
    parseInt(value / 1000) >= 1 ?
    (value / 1000).toFixed(1) + "k" :
    value;
})


// 时间规范
Vue.filter('delaytime', function (value) {
  if (!value) {
    return ""
  }
  let min = parseInt(value / 60) > 9 ? parseInt(value / 60) + "'" : "0" + parseInt(value / 60) + "'"
  let sec = parseInt(value % 60) > 9 ? parseInt(value % 60) + '"' : "0" + parseInt(value % 60) + '"'
  return min + sec
})
Vue.filter('picUrl', function (value) {
  if (!value) return ''
  return `${value}?x-oss-process=image/resize,m_mfit,w_720`
})
Vue.filter('publishtime', function (value) {
  if (!value) {
    return ""
  }
  let time = new Date(value * 1000);
  let now = new Date();
  let nowday = now.getDate();
  let year = time.getFullYear();
  let mou = (time.getMonth() + 1) >= 10 ? (time.getMonth() + 1) : '0' + (time.getMonth() + 1);
  let day = time.getDate() >= 10 ? time.getDate() : '0' + time.getDate();
  let interval = now - time;
  let years = parseInt(interval / (1000 * 3600 * 24 * 361));
  let mous = parseInt(interval / (1000 * 3600 * 24) % 12);
  let days = parseInt(interval / (1000 * 3600) % 24);
  if (years) {
    return year + '-' + mou + '-' + day
  } else if (mous) {
    return mou + '-' + day
  } else {
    if (parseInt(interval / 3600000) && parseInt(interval / 3600000) < 24) {
      return parseInt(interval / 3600000) + "小时前"
    } else if (parseInt(interval / 3600000) > 24) {
      return mou + '-' + day

    } else {
      return parseInt(interval / 60000) > 0 ? parseInt(interval / 60000) + "分钟前" : "刚刚"
    }
  }
})